#if CONFIG_IPMB_TESTER
#define CONFIG_IIC_DRIVER_TESTER 1

#ifndef  __IPMB_TEST_H__
#define  __IPMB_TEST_H__

#ifdef _cplusplus
extern "c"{
#endif

#include "Ipmb.h"
#include "IicDriverTester.h"
#include "IicCrb.h"

#define REQ_PACKET_SIZE 64
typedef struct _ReqPacket
{
	uint8  	m_Cmd; 
	
	uint8  	m_NetFn:6;		//MSB 
	
	uint8 	m_len;
	uint8	m_buff[REQ_PACKET_SIZE];
}ReqPacket;

typedef struct _TestPacket
{
	uint8		m_Cmd;		
	uint8		m_NetFn;	
	uint8		m_Len;		
	uint8		m_CmdData[REQ_PACKET_SIZE];	

	uint8		m_rspLen;				
	uint8		m_rspData[REQ_PACKET_SIZE];	
}TestPacket;

typedef struct _IicMsgPacket
{
	uint8 len;
	IicMsg m_IicMsg;
}IicMsgPacket;

typedef void (*IpmbRunFun)();

#define QUEUE_MAX_ELEMENT 32
#define IPMB_TEST_MAX_REQDATA_COUNT 16
typedef struct _IpmbTester
{
	Ipmb 	m_Ipmb;

	IicCrb			m_ReqCrb;
	IicCrb			m_RspCrb;
	
	TimerManager	m_TimerManager;
	Transfer		m_Transfer;

	IicDriver	m_IicDriver;

	Queue 		m_msgQueue;
	Message 	m_msgQueuePool[QUEUE_MAX_ELEMENT];
	
	Queue 	m_reqDataQueue;
	ReqData m_reqDataPool[IPMB_TEST_MAX_REQDATA_COUNT];

	IicCrb	m_FroReqCrb;
	IicCrb	m_FroRspCrb;
	IicCmd	m_receIicCmd;
}IpmbTester;

void IpmbTester_Init(IpmbTester* pIpmbTester
	, Queue* pRxQueue
	, Queue* pTxQueue
	, uint8 rA
	, uint8 rLun
	, uint8 lA
	, uint8 lLun
	, IpmbPostMsgFun PostMsg
	, CmdDisptchFun	 CmdDisptch
	);

uint8 IpmbTester_CmdDisptch(const IicMsg* pReq
	, uint8 reqlen
	, const IpmiCmdHandler* pTable
	, uint8 count
	, uint8* pRspBuff
	, uint8 rspBufLen
	);

void IpmbTester_Run(IpmbTester* pIpmbTester, IpmbRunFun IpmbRun);
int IpmbTester_PostMsg(IpmbTester* pIpmbTester, uint8 object, uint8 msgID, uint32 param1, uint32 param2);
int IpmbTester_ReqPlatformEvent(uint8* pReqCmd, uint8 Reqlen, uint8* pRspCmd, uint8* pRspLen);
void IpmbTester_SendReq(IpmbTester* pIpmbTester, TestPacket* pReq);
uint8 IpmbTester_GetRsp(IicMsg* pReq, IicMsg* pRsp, uint8* pCmdData, uint8 cmdLen);
void IpmbTester_CrbDone(IpmbTester* pIpmbTester, Crb* pCrb, uint8 State);
Bool IpmbTester_TxReqRxRsp(IpmbTester* pIpmbTester, TestPacket* pReq);
Bool IpmbTester_RxReqTxRsp(IpmbTester* pIpmbTester, TestPacket* pReq);
Bool IpmbTester_SendReqFailed(IpmbTester* pIpmbTester, TestPacket* pReq);
Bool IpmbTester_ReqNoRsp(IpmbTester* pIpmbTester, TestPacket* pReq);
Bool IpmbTester_ReSendReqRsp(IpmbTester* pIpmbTester, TestPacket* pReq, uint8 reSend);
Bool IpmbTester_RecInvalidPacket(IpmbTester* pIpmbTester, TestPacket* pReq, uint8 invalidByte);
Bool IpmbTester_RxMoreThenOneReq(IpmbTester* pIpmbTester, TestPacket* pReq, int nSendCount);
Bool IpmbTester_TxReqRxRspAndReq(IpmbTester* pIpmbTester, TestPacket * pTxReq, TestPacket * pRxReq);
uint8 IpmbTester_GetCmReq(ReqData* pReq, uint8 rsSA, uint8 rqSA, IicMsg* pCmReq, uint8 cmReqlen);

extern IpmbTester	g_IpmbTester;

#ifdef _cplusplus
}
#endif

#endif 

#endif
